<?php
class Line_route_model extends CI_Model
{
    private $table = 'line_route';
    
    public function saveLineRoute($line_id, $route)
    {
        $data = $this->convertArray($line_id, $route);
        return $this->db->insert_batch($this->table, $data);
    }
    
    /**
     * 将一维数组转换成多位数组
     * @param string $string
     * @param array $array
     * @return Ambigous <multitype:, array>
     */
    private function convertArray($string, array $array)
    {
        $data = $array;
        foreach ($array as $key=>$value) {
            $data[$key]['line_id'] = $string;
        }
        return $data;
    }
    
    public function findByLineId($line_id)
    {
        $this->db->where('line_id', $line_id);
        $this->db->order_by('route_day', 'ASC');
        return $this->db->get($this->table);
    }
    
    public function deleteByLineId($line_id)
    {
        $this->db->where('line_id', $line_id);
        return $this->db->delete($this->table);
    }
}